<?php
session_start();
//session_register('login_state');
//$_SESSION['login_state'] ;
//===========================================================
$path = '../';
include($path."common.php");
include($path."prod_fun.php");
//=========================================================== 
$pageout = "prod_login.php" ; 
//echo $login_state ;
if($_SESSION['login_state'] <> "S" and $_SESSION['login_state'] <> "P"){
	gotopage($pageout) ;
}
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="../css/cart.css" />
<style>
.hint{
position:absolute;
display : none;
width:300px;
font-size:11px;
color:#666 ;
background:#FFFFFF;
border:#360 1px dotted;
padding:6px;
z-index: 5 ;
}
</style>
<script language="javascript">

function moveBoard(d) {
var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0; 
var scrollLeft = window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft || 0;

var b = document.getElementById(d) ;
b.style.left = (document.body.clientWidth - b.offsetWidth) / 2 + scrollLeft; 
b.style.top = (document.body.clientHeight - b.offsetHeight) / 2 + scrollTop; 
}  


function show_win(d){
//使select失效
var selObj=document.getElementsByTagName("select");
for(var i=0;i<selObj.length;i++)
{
selObj[i].disabled=true;
}
//產生背景
document.body.appendChild(bgObj); 
//顯示表單
document.getElementById(d).style.display = 'block' ;
window.onresize = moveBoard(d) ;
window.onscroll = moveBoard(d) ;
//window.onresize = function() {moveBoard(d);};
//window.onscroll = function() {moveBoard(d);};
}

function close_win(id){
document.body.removeChild(bgObj);
document.getElementById(id).style.display = 'none' ;
}



var xmlHttp;
function createXHR(){
	if (window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
	}else if (window.ActiveXObject) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}

	if (!xmlHttp) {
		alert('您使用的瀏覽器不支援 XMLHTTP 物件');
		return false;
	}
}

function sendRequest(url){
	createXHR() ;
	xmlHttp.open('GET',url,true) ;
	xmlHttp.onreadystatechange = catchXML ;
	xmlHttp.send(null) ;
}

function catchXML(){
	if (xmlHttp.readyState==4){
		xml=xmlHttp.responseXML;
		if (xmlHttp.status == 200) {
//            document.getElementById('s').innerHTML=xmlHttp.responseText ;
			location.reload() ;
		}else{
			alert('執行錯誤,代碼:'+xmlHttp.status+'\('+xmlHttp.statusText+'\)');
		}
	}
}



</script>
<?

$sql = "select * from product order by id " ;
$result = mysql_query($sql);

$site = "prod_list.php" ;
$pagesize = 10; //每頁筆數
$numrows = mysql_num_rows($result) ; //總筆數
$totalpages = ceil($numrows / $pagesize); //頁數、最後一頁頁碼
if(!isset($_GET["page"])){
$currentpage = 1 ;
}else{
$currentpage = $_GET['page'] ;
}
$startnum = ($currentpage -1) * $pagesize;   //開始的筆數
$startnum = $startnum < 0 ? 0 : $startnum;


//===========================================================
echo "<form method=post id=frm_list name=frm_list action=\"prod_act.php?nowpage=$nowpage\">" ;
echo "<table width=100% border=1 align=center>" ;

echo "<tr>" ;
echo "<td align=left colspan=11><input name=action type=submit value='新增資料'>" ;
echo "<input name=update_ml type=button value='運費及分期利率管理' onclick=\"show_win('c');edit.location.reload();\">" ;
echo "</td>" ;
echo "<td align=right><input name=action type=submit value='登出'>" ;
echo "</td>" ;
echo "</tr>" ;
echo "<tr>" ;
echo "<td width=12% align=center>產品編號</td>" ;
echo "<td width=30% align=center>產品名稱</td>" ;
echo "<td width=12% align=center>產品數量</td>" ;
echo "<td width=12% align=center>市售價</td>" ;
echo "<td width=12% align=center>公益價</td>" ;
echo "<td align=center>3期分期售價</td>" ;
echo "<td align=center>6期分期售價</td>" ;
echo "<td align=center>12期分期售價</td>" ;
echo "<td align=center>24期分期售價</td>" ;
echo "<td width=5% align=center>編輯</td>" ;
echo "<td width=5% align=center>刪除</td>" ;
echo "<td width=12% align=center>查詢代碼</td>" ;
echo "</tr>" ;
//===========================================================
$act_up = urlencode("修改資料") ;
$act_del = urlencode("刪除") ;

$sql_list = "select * from product order by id limit $startnum,$pagesize" ;
$result_list = mysql_query($sql_list);
while($row_list=mysql_fetch_object($result_list)){
$prodno = $row_list->id ;
$prodname = $row_list->name ;
$prodqty = $row_list->pd_count ;
$prodpric1 = $row_list->price_1 ;
$prodpric2 = $row_list->price_2 ;


$sql_rate = "select * from stage " ;
$result_rate = mysql_query($sql_rate);
$row_rate=mysql_fetch_object($result_rate) ;
$rate_1 = $row_rate->three_rate ;
$rate_2 = $row_rate->six_rate ;
$rate_3 = $row_rate->twelve_rate ;
$rate_4 = $row_rate->tf_rate ;

$pric_rate3 = $prodpric2 * (($rate_1+100)/100) ;
$pric_rate6 = $prodpric2 * (($rate_2+100)/100) ;
$pric_rate12 = $prodpric2 * (($rate_3+100)/100) ;
$pric_rate24 = $prodpric2 * (($rate_4+100)/100) ;

echo "<tr height=20>" ;
echo "<td align=center>".$prodno."</td>" ;
echo "<td>".$prodname."</td>" ;
echo "<td align=center>".$prodqty."</td>" ;
echo "<td align=center>".$prodpric1."</td>" ;
echo "<td align=center>".$prodpric2."</td>" ;
echo "<td align=center>".floor($pric_rate3)."</td>" ;
echo "<td align=center>".floor($pric_rate6)."</td>" ;
echo "<td align=center>".floor($pric_rate12)."</td>" ;
echo "<td align=center>".floor($pric_rate24)."</td>" ;
echo "<td align=center>"."<input name=action type=button value='修改資料' onclick=\"location.href='prod_act.php?action=$act_up&pid=$prodno&nowpage=$currentpage'\">"."</td>" ;
echo "<td align=center>"."<input name=action type=button value='刪除資料' onclick=\"if(!confirm('確定刪除？')){return false;};sendRequest('prod_act.php?action=$act_del&pid=$prodno&ts='+new Date().getTime());\">"."</td>" ;
echo "<td align=center>"."<input name=action type=button value='查詢' onclick=\"window.open('prod_code.php?pid=$prodno', 'code', config='height=300,width=450,toolbar=no,resizable=no,top=100,left=600')\">"."</td>" ;
echo "</tr>" ;
}
//===========================================================
echo "</table>" ;
echo "</form>" ;
//===========================================================
echo "<table width=100% border=0 align=center>" ;
echo "<tr><td align=center>" ;
fenye($site,$currentpage,$totalpages) ;
echo "</td></tr>" ;
echo "</table>" ;
//===========================================================
echo "<div id=c class=hint >" ;
echo "<table width=100% border=0 align=center cellpadding=1 cellspacing=1>" ;
echo "<tr><td><iframe src=\"prod_stage.php\" id=edit name=edit scrolling=no height=300 frameborder=0></iframe></td></tr>" ;
echo "</table>" ;
echo "</div>" ;
?>

<script language="javascript">
var bgObj = document.createElement('div');
var iWidth = document.body.clientWidth;
var iHeight = document.body.clientHeight;
bgObj.style.cssText = "position:absolute;left:0px;top:0px;width:"+iWidth+"px;height:"+Math.max(document.body.clientHeight, iHeight)+"px;filter:Alpha(Opacity=30);opacity:0.3;background-color:#000000;z-index:2;";
</script>